package cn.fl.audit.service.impl;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.api.ISysRegionApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.comm.facade.framework.dto.SysRegionDTO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.audit.condition.AudCreditInfoQueryCondition;
import cn.fl.audit.dto.AudCreditInfoDTO;
import cn.fl.audit.dto.AudReturnVisitDTO;
import cn.fl.audit.dto.AudVisitTkDTO;
import cn.fl.audit.service.IAudCreditInfoService;
import cn.fl.audit.service.IAuditApiService;
import cn.fl.audit.transform.AudCreditInfoVOTransform;
import cn.fl.audit.vo.AudCreditInfoVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.preloan.IAuditCreditInfoService;
import cn.fl.preloan.IAuditReturnVisitService;
import cn.fl.preloan.condition.AuditCreditInfoQueryCondition;
import cn.fl.preloan.condition.AuditReturnVisitQueryCondition;
import cn.fl.preloan.dto.audit.*;
import cn.fl.project.constant.PrjBscInfoConstant;
import cn.fl.project.service.IProjectApiService;
import com.alibaba.fastjson.JSONObject;
import fl.flow.facade.flow.api.IFlowQueryApiService;
import fl.flow.facade.flow.condition.SysFlowSHQueryCondition;
import fl.flow.facade.flow.dto.SysFlowSHDTO;
import cn.fl.commons.result.ResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 信审整体资料 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class AudCreditInfoServiceImpl implements IAudCreditInfoService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(AudCreditInfoServiceImpl.class);
	
	/**
	 * 信审 API 暴露服务
	 */
	@Autowired
	private IAuditApiService auditApiService;
	
	/**
	 * 项目 API 暴露服务
	 */
	@Autowired
	private IProjectApiService projectApiService;
	
	/**
	 * 数据字典服务
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	
	/**
	 * 区域信息服务
	 */
	@Autowired
	private ISysRegionApiService sysRegionApiService;
	
	/**
	 * 查询流程API 暴露服务
	 */
	@Autowired
	private IFlowQueryApiService flowQueryApi;

	@Autowired
	private IAuditCreditInfoService auditCreditInfoService;

	@Autowired
	private IAuditReturnVisitService auditReturnVisitService;

	@Override
	public AudCreditInfoVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		AudCreditInfoDTO dto = null;//this.自定义ApiService.selectById(id);
		return AudCreditInfoVOTransform.toVO(dto);
	}

	@Override
	public Long add(AudCreditInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		return this.auditApiService.addAudCreditInfo(AudCreditInfoVOTransform.toDTO(entity), CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.audCreditInfoApiService.removeById(id);
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(AudCreditInfoVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.auditApiService.modifyAudCreditInfo(AudCreditInfoVOTransform.toDTO(entity), CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		//return this.audCreditInfoApiService.searchListPage(page);
		return null;
	}

	@Override
	public AudCreditInfoVO selectAudCreditInfoByQc(AuditCreditInfoQueryCondition qc) throws BaseException {
		if(null==qc || null==qc.getProjectId() || StringUtils.isEmpty(qc.getProIntId())){
			BaseLogUtils.info(logger, "searchAudCreditInfo", "查询信审整体资料对象失败,缺少必要的的参数条件,项目ID或流程实例ID.DATA:"+JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, BaseExceptionConstant.BASE_EXCEPTION_CODE_604_NAME);
		}
		//调API查询信审整体资料信息
		List<AuditCreditInfoDTO> searchAudCreditInfoList = new ArrayList<>();
		AuditCreditInfoDTO audCreditInfoDTO = new AuditCreditInfoDTO();
		AudCreditInfoListRequest listRequest = new AudCreditInfoListRequest(qc, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		ResponseData<List<AuditCreditInfoDTO>> responseData = auditCreditInfoService.searchList(listRequest);
		if (responseData != null && ResponseData.SUCCESS_CODE.equals(responseData.getCode()) && CollectionUtils.isNotEmpty(responseData.getData())) {
			searchAudCreditInfoList = responseData.getData();
		}
		if(CollectionUtils.isNotEmpty(searchAudCreditInfoList)){
			audCreditInfoDTO = searchAudCreditInfoList.get(0);
			//判断相关字段是否为空   为空则查询回访 取值保存并返回   
			if(StringUtils.isEmpty(audCreditInfoDTO.getSelfTkDesc())	//自有车辆情况
					|| StringUtils.isEmpty(audCreditInfoDTO.getProfitCd())	//收入方式
					|| StringUtils.isEmpty(audCreditInfoDTO.getExperience())	//运营年限
					|| StringUtils.isEmpty(audCreditInfoDTO.getMainGoodsCd())	//主货物大类
					|| StringUtils.isEmpty(audCreditInfoDTO.getGoods())	//主运输货物
					|| StringUtils.isEmpty(audCreditInfoDTO.getRoute())	//运营路线
					|| StringUtils.isEmpty(audCreditInfoDTO.getGoodsResCd())	//货物来源
					|| StringUtils.isEmpty(audCreditInfoDTO.getSettlementTypeCd())	//主货物结算方式
					|| StringUtils.isEmpty(audCreditInfoDTO.getDriverInfo())	//司机情况
					|| StringUtils.isEmpty(audCreditInfoDTO.getSecondPayResCd())	//第二还款来源
					|| StringUtils.isEmpty(audCreditInfoDTO.getNetIncome())	//净收入
					|| StringUtils.isEmpty(audCreditInfoDTO.getHighEasonCharterdBus())	//旺季包车费
					|| StringUtils.isEmpty(audCreditInfoDTO.getPeakEasonCharterdBus())	//淡季包车费
					|| null==audCreditInfoDTO.getOtherFeePct()	//其他费用占比
					|| StringUtils.isEmpty(audCreditInfoDTO.getGrossIncome())	//毛收入
					|| StringUtils.isEmpty(audCreditInfoDTO.getOtherInfo())	//其他信息
				    || StringUtils.isEmpty(audCreditInfoDTO.getCircuitType())//
					|| StringUtils.isEmpty(audCreditInfoDTO.getCargoWeigth())	//其他信息
					|| StringUtils.isEmpty(audCreditInfoDTO.getCargoVomule())	//其他信息
					|| StringUtils.isEmpty(audCreditInfoDTO.getHandlingMode())	//其他信息
					|| StringUtils.isEmpty(audCreditInfoDTO.getCircuitEfficiency())	//其他信息
					|| StringUtils.isEmpty(audCreditInfoDTO.getFare())){	//其他信息

				AuditReturnVisitQueryCondition returnQC = new AuditReturnVisitQueryCondition();
				returnQC.setProjectId(qc.getProjectId());
				AudReturnVisitListRequest searchRequest = new AudReturnVisitListRequest();
				searchRequest.setCondition(returnQC);
				searchRequest.setSysCd(CurrentThreadContext.getCurrentSysCd());
				searchRequest.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
				ResponseData<List<AuditReturnVisitDTO>> listResponseData = auditReturnVisitService.searchAudReturnVisitList(searchRequest);
				List<AuditReturnVisitDTO> DTOList = new ArrayList<>();
				if (listResponseData != null && ResponseData.SUCCESS_CODE.equals(listResponseData.getCode()) && CollectionUtils.isNotEmpty(listResponseData.getData())) {
					DTOList = listResponseData.getData();
				}

				if(CollectionUtils.isNotEmpty(DTOList)){
					AuditReturnVisitDTO audReturnVisitDTO = DTOList.get(0);
					if(null!=audReturnVisitDTO){
						AuditVisitTkDTO audVisitTkDTO = audReturnVisitDTO.getAudVisitTkDTO();
						if(null!=audVisitTkDTO){
							if(StringUtils.isEmpty(audCreditInfoDTO.getSelfTkDesc())){
								audCreditInfoDTO.setSelfTkDesc(audVisitTkDTO.getSelfTkDesc());//自有车辆情况
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getProfitCd())){
								audCreditInfoDTO.setProfitCd(audVisitTkDTO.getProfitCd());//收入方式
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getExperience())){
								audCreditInfoDTO.setExperience(audVisitTkDTO.getBizExp());//运营年限
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getMainGoodsCd())){
								audCreditInfoDTO.setMainGoodsCd(audVisitTkDTO.getMainGdsTypCd());//主货物大类
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getGoods())){
								audCreditInfoDTO.setGoods(audVisitTkDTO.getGoods());//主运输货物
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getRoute())){
								audCreditInfoDTO.setRoute(audVisitTkDTO.getRoute());//运营路线
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getGoodsResCd())){
								audCreditInfoDTO.setGoodsResCd(audVisitTkDTO.getGoodsRes());//货物来源
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getSettlementTypeCd())){
								audCreditInfoDTO.setSettlementTypeCd(audVisitTkDTO.getGdsStlWayCd());//主货物结算方式
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getDriverInfo())){
								audCreditInfoDTO.setDriverInfo(audVisitTkDTO.getDriver());//司机情况
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getSecondPayResCd())){
								audCreditInfoDTO.setSecondPayResCd(audVisitTkDTO.getSecondPayResCd());//第二还款来源
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getNetIncome())){
								audCreditInfoDTO.setNetIncome(audVisitTkDTO.getNetIncome());//净收入
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getHighEasonCharterdBus())){
								audCreditInfoDTO.setHighEasonCharterdBus(audVisitTkDTO.getHighEasonCharterdBus());//旺季包车费
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getPeakEasonCharterdBus())){
								audCreditInfoDTO.setPeakEasonCharterdBus(audVisitTkDTO.getPeakEasonCharterdBus());//淡季包车费
							}
							if(null==audCreditInfoDTO.getOtherFeePct()){
								audCreditInfoDTO.setOtherFeePct(audVisitTkDTO.getOtherFeePct());//其他费用占比
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getGrossIncome())){
								audCreditInfoDTO.setGrossIncome(audVisitTkDTO.getGrossIncome());//毛收入
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getOtherInfo())){
								audCreditInfoDTO.setOtherInfo(audVisitTkDTO.getOtherInfo());//其他信息
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getCircuitType())){
								audCreditInfoDTO.setCircuitType(audReturnVisitDTO.getCircuitType());
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getCargoWeigth())){
								audCreditInfoDTO.setCargoWeigth(audReturnVisitDTO.getCargoWeigth());
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getCargoVomule())){
								audCreditInfoDTO.setCargoVomule(audReturnVisitDTO.getCargoVomule());
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getHandlingMode())){
								audCreditInfoDTO.setHandlingMode(audReturnVisitDTO.getHandlingMode());
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getCircuitEfficiency())){
								audCreditInfoDTO.setCircuitEfficiency(audReturnVisitDTO.getCircuitEfficiency());
							}
							if(StringUtils.isEmpty(audCreditInfoDTO.getFare())){
								audCreditInfoDTO.setFare(audReturnVisitDTO.getFare());
							}

							ModifyAudCreditInfoRequest modifyRequest=new ModifyAudCreditInfoRequest(audCreditInfoDTO, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
							ResponseData modifyResponse = auditCreditInfoService.modifyAudCreditInfo(modifyRequest);
							if(!ResponseData.SUCCESS_CODE.equals(modifyResponse.getCode())){
								throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_603, BaseExceptionConstant.BASE_EXCEPTION_CODE_602_NAME);
							}
						}
					}
				}
			}
		}else{
			//没查询到信审整理资料 -> 查询回访 
			AuditReturnVisitQueryCondition returnQC = new AuditReturnVisitQueryCondition();
			returnQC.setProjectId(qc.getProjectId());
			AudReturnVisitListRequest searchRequest = new AudReturnVisitListRequest();
			searchRequest.setCondition(returnQC);
			searchRequest.setSysCd(CurrentThreadContext.getCurrentSysCd());
			searchRequest.setOrgCd(CurrentThreadContext.getCurrentOrgCd());
			ResponseData<List<AuditReturnVisitDTO>> listResponseData = auditReturnVisitService.searchAudReturnVisitList(searchRequest);
			List<AuditReturnVisitDTO> DTOList = new ArrayList<>();
			if (listResponseData != null && ResponseData.SUCCESS_CODE.equals(listResponseData.getCode()) && CollectionUtils.isNotEmpty(listResponseData.getData())) {
				DTOList = listResponseData.getData();
			}

			if(CollectionUtils.isNotEmpty(DTOList)){
				AuditReturnVisitDTO audReturnVisitDTO = DTOList.get(0);
				if(null!=audReturnVisitDTO){
					AuditVisitTkDTO audVisitTkDTO = audReturnVisitDTO.getAudVisitTkDTO();
					if(null!=audVisitTkDTO){
						audCreditInfoDTO.setSelfTkDesc(audVisitTkDTO.getSelfTkDesc());
						audCreditInfoDTO.setProfitCd(audVisitTkDTO.getProfitCd());
						audCreditInfoDTO.setExperience(audVisitTkDTO.getBizExp());
						audCreditInfoDTO.setMainGoodsCd(audVisitTkDTO.getMainGdsTypCd());
						audCreditInfoDTO.setGoods(audVisitTkDTO.getGoods());
						audCreditInfoDTO.setRoute(audVisitTkDTO.getRoute());
						audCreditInfoDTO.setGoodsResCd(audVisitTkDTO.getGoodsRes());
						audCreditInfoDTO.setSettlementTypeCd(audVisitTkDTO.getGdsStlWayCd());
						audCreditInfoDTO.setDriverInfo(audVisitTkDTO.getDriver());
						audCreditInfoDTO.setSecondPayResCd(audVisitTkDTO.getSecondPayResCd());
						audCreditInfoDTO.setOtherInfo(audVisitTkDTO.getOtherInfo());
						audCreditInfoDTO.setNetIncome(audVisitTkDTO.getNetIncome());
						audCreditInfoDTO.setHighEasonCharterdBus(audVisitTkDTO.getHighEasonCharterdBus());
						audCreditInfoDTO.setPeakEasonCharterdBus(audVisitTkDTO.getPeakEasonCharterdBus());
						audCreditInfoDTO.setOtherFeePct(audVisitTkDTO.getOtherFeePct());
						audCreditInfoDTO.setGrossIncome(audVisitTkDTO.getGrossIncome());
					}
					audCreditInfoDTO.setCircuitType(audReturnVisitDTO.getCircuitType());
					audCreditInfoDTO.setCargoWeigth(audReturnVisitDTO.getCargoWeigth());
					audCreditInfoDTO.setCargoVomule(audReturnVisitDTO.getCargoVomule());
					audCreditInfoDTO.setHandlingMode(audReturnVisitDTO.getHandlingMode());
					audCreditInfoDTO.setCircuitEfficiency(audReturnVisitDTO.getCircuitEfficiency());
					audCreditInfoDTO.setFare(audReturnVisitDTO.getFare());
				}
			}
		}

		AudCreditInfoVO audCreditInfoVO = new AudCreditInfoVO();
		BeanUtils.copyProperties(audCreditInfoDTO, audCreditInfoVO);
		audCreditInfoVO.setHouseCret(audCreditInfoDTO.getHouseCert());
		audCreditInfoVO.setFareType(audCreditInfoDTO.getFareTypeCd());
		audCreditInfoVO.setChargingType(audCreditInfoDTO.getChargingTypeCd());
		audCreditInfoVO.setHandingMode(audCreditInfoDTO.getHandlingMode());

		//设置实际区域名称
		String actualAreaCd = audCreditInfoVO.getActualAreaCd();
		if(StringUtils.isNotEmpty(actualAreaCd)){
			SysRegionDTO sysRegionDTO = this.sysRegionApiService.getRegionByRgnCd(actualAreaCd, CurrentThreadContext.getCurrentSysCd());
			audCreditInfoVO.setActualAreaCdNm(sysRegionDTO.getRgnNm());
		}
		/**
		 * 金额处理-月净收入|月还款|...农机相关字段类型后续待确认
		 */
		if(null!=audCreditInfoVO.getMonthIncome()){
			audCreditInfoVO.setMonthIncomeDouble(DecimalUtils.convertFenToYuan(audCreditInfoVO.getMonthIncome()));
		}
		if(null!=audCreditInfoVO.getMonthRepayment()){
			audCreditInfoVO.setMonthRepaymentDouble(DecimalUtils.convertFenToYuan(audCreditInfoVO.getMonthRepayment()));
		}
		return audCreditInfoVO;
	}

	@Override
	public List<KeyValueVO> searchGoodsTypListByLvl(String lvl) throws BaseException {
		if(StringUtils.isEmpty(lvl)) return null;
		List<KeyValueVO> kvList = new ArrayList<>();
		try {
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroupWithLevel(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), DictionaryConstant.CODE_AUD_GOODS_TYP_CD, Integer.valueOf(lvl));
			if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
				for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(sysDictionaryDTO.getCode());
					keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
					kvList.add(keyValueVO);
				}
			}
		} catch (BaseException e) {
			BaseLogUtils.info(logger, "getKvList", "获取字典项组"+DictionaryConstant.CODE_AUD_GOODS_TYP_CD+"失败.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception e) {
			BaseLogUtils.error(logger, "getKvList", "获取字典项组"+DictionaryConstant.CODE_AUD_GOODS_TYP_CD+"失败,系统错误.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return kvList;
	}

	@Override
	public List<KeyValueVO> searchGoodsTypListByPCode(String PCode) throws BaseException {
		if(StringUtils.isEmpty(PCode)) return null;
		List<KeyValueVO> kvList = new ArrayList<>();
		try {
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchChild(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentBuOrgCd(), DictionaryConstant.CODE_AUD_GOODS_TYP_CD, PCode);
			if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
				for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(sysDictionaryDTO.getCode());
					keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
					kvList.add(keyValueVO);
				}
			}
		} catch (BaseException e) {
			BaseLogUtils.info(logger, "getKvList", "获取字典项组"+DictionaryConstant.CODE_AUD_GOODS_TYP_CD+"失败.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception e) {
			BaseLogUtils.error(logger, "getKvList", "获取字典项组"+DictionaryConstant.CODE_AUD_GOODS_TYP_CD+"失败,系统错误.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return kvList;
	}

	@Override
	public List<KeyValueVO> searchIsMeetPolicyCdList() throws BaseException {
		return this.getKvList(DictionaryConstant.CODE_AUD_IS_MEET_POLICY_CD);
	}
	
	/**
	 * 根据字典中代码组值获取组员集合
	 * @param grpCd 代码组值
	 * @return 集合
	 */
	private List<KeyValueVO> getKvList(String grpCd){
		List<KeyValueVO> kvList = new ArrayList<>();
		try {
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), grpCd);
			if(CollectionUtils.isNotEmpty(sysDictionaryDTOList)){
				for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(sysDictionaryDTO.getCode());
					keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
					kvList.add(keyValueVO);
				}
			}
		} catch (BaseException e) {
			BaseLogUtils.info(logger, "getKvList", "获取字典项组"+grpCd+"失败.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception e) {
			BaseLogUtils.error(logger, "getKvList", "获取字典项组"+grpCd+"失败,系统错误.ERROR:"+e.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return kvList;
	}

	/**
     * 根据 项目ID 查询唯一信审整体资料
     * @author JL 20190819
     * @param qc
     * @return
     * @throws BaseException
     */
	@Override
	public AudCreditInfoVO getAudCreditInfoByQc(AuditCreditInfoQueryCondition qc) throws BaseException {
		if(null==qc || StringUtils.isEmpty(qc.getProjectId())){
			BaseLogUtils.info(logger, "getAudCreditInfoByQc", "查询信审整体资料对象失败,缺少必要的的参数条件,项目ID.DATA:"+JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
		}
		//1.根据 项目ID 查询 流程实例ID
		SysFlowSHQueryCondition sysFlowSHQC = new SysFlowSHQueryCondition();
		sysFlowSHQC.setDataId(qc.getProjectId());
		sysFlowSHQC.setWordsInTheTable(PrjBscInfoConstant.PRJ_FLOW_S_H_PRJ);
		sysFlowSHQC.setSysCd(CurrentThreadContext.getCurrentSysCd());
		sysFlowSHQC.setStatus(BaseConstant.IS_YESNO_YES); //数据状态(是否最新0:否 1:是)
		List<SysFlowSHDTO> sysFlowSHList = this.flowQueryApi.searchFlowSHList(sysFlowSHQC);
		if(CollectionUtils.isNotEmpty(sysFlowSHList)){
			SysFlowSHDTO sysFlowSHDTO = sysFlowSHList.get(0);
			qc.setProIntId(sysFlowSHDTO.getPInstId()); //流程实例ID
		}
		BaseLogUtils.info(logger, "getAudCreditInfoByQc", "查询信审整体资料,参数条件:"+JSONObject.toJSONString(qc), CurrentThreadContext.getCurrentUserName());
		//2.调API查询信审整体资料信息
		AuditCreditInfoDTO audCreditInfoDTO = new AuditCreditInfoDTO();
		AudCreditInfoListRequest listRequest = new AudCreditInfoListRequest(qc, CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd());
		ResponseData<List<AuditCreditInfoDTO>> responseData = auditCreditInfoService.searchList(listRequest);
		BaseLogUtils.info(logger, "getAudCreditInfoByQc", "查询信审整体资料,结果:"+JSONObject.toJSONString(responseData), CurrentThreadContext.getCurrentUserName());
		if (responseData != null && ResponseData.SUCCESS_CODE.equals(responseData.getCode()) && CollectionUtils.isNotEmpty(responseData.getData())) {
			audCreditInfoDTO = responseData.getData().get(0);
		}
		AudCreditInfoVO audCreditInfoVO = new AudCreditInfoVO();
		BeanUtils.copyProperties(audCreditInfoDTO, audCreditInfoVO);
		audCreditInfoVO.setHouseCret(audCreditInfoDTO.getHouseCert());
		audCreditInfoVO.setFareType(audCreditInfoDTO.getFareTypeCd());
		audCreditInfoVO.setChargingType(audCreditInfoDTO.getChargingTypeCd());
		audCreditInfoVO.setHandingMode(audCreditInfoDTO.getHandlingMode());
		return audCreditInfoVO;
	}
}
